<?php


namespace app\api\controller\xilujob;


use app\common\controller\xilujob\XilujobApi;
use app\common\model\xilujob\UserFeedback;
use think\Db;

class Feedback extends XilujobApi
{
    protected $noNeedLogin = ['feedback_reasons'];
    protected $noNeedRight = ['*'];
    protected $restrictedActions = ['*'];


    /**
     * @ApiTitle (意见反馈类型)
     * @ApiMethod (GET)
     * @ApiRoute (/api/xilujob.common/feedback_reasons)
     */
    public function feedback_reasons() {
        $reason = Db::name('xilujob_feedback_type')->field('id,name')->where('status','1')->order('weigh','asc')->select();
        $this->success('类型查询成功',['feedback_reasons'=>$reason]);
    }

    /**
     * @ApiTitle (意见反馈提交)
     * @ApiMethod (POST)
     * @ApiRoute (/api/xilujob.common/feedback)
     * @ApiHeaders (name=token, type=string, description="Token")
     * @ApiParams (name="contact", type="string", description="联系电话")
     * @ApiParams (name="content", type="string", description="反馈内容")
     * @ApiParams (name="images", type="string", description="反馈内容图片")
     * @ApiParams (name="reason", type="string", description="反馈类型")
     */
    public function feedback() {
        $params = $this->request->post('',null,'trim,strip_tags');
        $feedback = new UserFeedback();
        $params['user_id'] = $this->auth->id;
        $ret = $feedback->save($params);
        if($ret===false) {
            $this->error($feedback->getError());
        }
        $this->success('提交成功');
    }

}